import Vue from 'vue';
import VueRouter from 'vue-router';
import {setting} from '@/setting.js'
import BasicLayout from '@/layouts/basic-layout/index.vue';

Vue.use(VueRouter);
let routes = [
    {
        path: "/",
        redirect: {
            name: 'home'
        },
        component: BasicLayout,
        children:[
            {
                path: 'home',
                name: `home`,
                meta: {
                    title: '首页',
                },
                component: () => import('@/pages/home/index.vue')
            },
        ]
    }
]
//根据模块配置注册测试路由
_.forEach(setting, (item, key) => {
    _.forEach(item.pages,(child)=>{
        //测试页面
        routes[0]['children'].push({
            path: `/examples/${key}/${child.key}`,
            component: () => import(`@/examples/${key}/${child.key}/index.vue`),
            name: `${key}.${child.key}`,
            meta: {
                title: item.name,
            },
        });
    })
})


// 导出路由 在 main.js 里使用
const router = new VueRouter({
    routes,
    mode: 'history',
    base: '/'
});


/**
 * 路由前置守卫
 */
router.beforeEach(async (to, from, next) => {
    next();
});

/**
 * 路由后置守卫
 */
router.afterEach((to, from, next) => {

})

export default router;
